<template>
  <div id="mymeeting">
    <el-breadcrumb>
      <el-breadcrumb-item>个人中心</el-breadcrumb-item>
      <el-breadcrumb-item>我的会议</el-breadcrumb-item>
    </el-breadcrumb>
    <div id="main">
      <el-form :inline="true" :model="searchData" class="demo-form-inline">
        <el-form-item label="会议主题">
          <el-input v-model="searchData.tit"></el-input>
        </el-form-item>
        <el-form-item label="发起人">
          <el-input v-model="searchData.per"></el-input>
        </el-form-item>
        <el-form-item label="会议时间">
          <div class="block">
            <el-date-picker
              v-model="searchData.mytime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="info" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
      <div id="line"></div>
      <el-button type="primary" id="process" @click="meetingfn"
        >发起会议</el-button
      >
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="meeting_tit" label="会议主题" width="150px">
        </el-table-column>
        <el-table-column prop="metroom_name" label="会议室名称" width="150px">
        </el-table-column>
        <el-table-column prop="meeting_startime" label="开始时间" width="200px">
        </el-table-column>
        <el-table-column prop="meeting_endtime" label="结束时间" width="200px">
        </el-table-column>
        <el-table-column prop="meeting_length" label="会议时长" width="150px">
        </el-table-column>
        <el-table-column prop="name" label="发起人" width="150px">
        </el-table-column>
        <el-table-column prop="meeting_todotime" label="操作时间">
        </el-table-column>
      </el-table>
      <div class="block block2">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="count"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalpage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchData: {
        mytime: "",
        tit: "",
        per: "",
      },
      searchData2: [],
      totaldata: [],
      currentPage4: 1,
      count: 5,
      mypage: "",
    };
  },
  methods: {
    onSubmit() {
      this.currentPage4 = 1;
      if (
        this.searchData.mytime ||
        this.searchData.tit ||
        this.searchData.per
      ) {
        let mytime = this.searchData.mytime ? this.searchData.mytime : "";
        let tit = this.searchData.tit ? this.searchData.tit : "";
        let per = this.searchData.per ? this.searchData.per : "";
        this.page = 1;
        this.searchData2 = [tit, per, mytime];
      } else {
        this.searchData = "";
      }
    },
    reset() {
      this.currentPage4 = 1;
      this.show();
      this.totaldata = [];
      this.searchData = {};
      this.searchData2 = [];
    },
    handleSizeChange(n) {
      this.count = n;
    },
    handleCurrentChange(n) {
      this.currentPage4 = n;
    },
    meetingfn() {
      this.$router.push("/home/meeting");
    },
    show() {
      // console.log(this.$store.state.data.post_department);
      this.$axios({
        url: "/personalcenter/meeting/get",
        params: {
          department: JSON.parse(sessionStorage.getItem("user"))
            .post_department,
        },
      }).then((res) => {
        res.data.data.forEach((v, i) => {
          let date1 = new Date(v.meeting_startime);
          let date2 = new Date(v.meeting_endtime);
          let total = (date2.getTime() - date1.getTime()) / 1000 / 60 / 60;
          v.meeting_length = total + "小时";
          this.totaldata.push(v);
        });
      });
    },
  },

  computed: {
    totalpage: function () {
      if (this.searchData2.length != 0) {
        return this.mypage;
      } else {
        return this.totaldata.length;
      }
    },
    tableData: function () {
      if (this.searchData2.length != 0) {
        this.mypage = 0;
        let arr = [];
        for (let i = 0; i < this.totaldata.length; i++) {
          if (
            new Date(this.totaldata[i].meeting_todotime) >=
              new Date(this.searchData2[2][0]) &&
            new Date(this.totaldata[i].meeting_todotime) <=
              new Date(this.searchData2[2][1]) &&
            this.totaldata[i].meeting_tit == this.searchData2[0] &&
            this.totaldata[i].name == this.searchData2[1]
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            new Date(this.totaldata[i].meeting_todotime) >=
              new Date(this.searchData2[2][0]) &&
            new Date(this.totaldata[i].meeting_todotime) <=
              new Date(this.searchData2[2][1]) &&
            this.totaldata[i].meeting_tit == this.searchData2[0]
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            this.totaldata[i].meeting_tit == this.searchData2[0] &&
            this.totaldata[i].name == this.searchData2[1]
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            new Date(this.totaldata[i].meeting_todotime) >=
              new Date(this.searchData2[2][0]) &&
            new Date(this.totaldata[i].meeting_todotime) <=
              new Date(this.searchData2[2][1]) &&
            this.totaldata[i].name == this.searchData2[1]
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            this.totaldata[i].name == this.searchData2[1] &&
            this.searchData2[0] == "" &&
            this.searchData2[2] == ""
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            this.totaldata[i].meeting_tit == this.searchData2[0] &&
            this.searchData2[2] == "" &&
            this.searchData2[1] == ""
          ) {
            arr.push(this.totaldata[i]);
          } else if (
            new Date(this.totaldata[i].meeting_todotime) >=
              new Date(this.searchData2[2][0]) &&
            new Date(this.totaldata[i].meeting_todotime) <=
              new Date(this.searchData2[2][1]) &&
            this.searchData2[0] == "" &&
            this.searchData2[1] == ""
          ) {
            arr.push(this.totaldata[i]);
          }
        }
        this.mypage = arr.length;
        return arr.slice(
          (this.currentPage4 - 1) * this.count,
          this.currentPage4 * this.count
        );
      } else {
        return this.totaldata.slice(
          (this.currentPage4 - 1) * this.count,
          this.currentPage4 * this.count
        );
      }
    },
  },
  created() {
    this.show();
  },
};
</script>
<style lang="less" scoped>
#mymain {
  margin-top: 20px;
}
#main {
  margin-top: 20px;
  height: 70%;
  background-color: white;
  height: 100%;
  padding: 20px;
}
.el-menu {
  padding-left: 20px;
}
.el-form-item {
  margin-right: 20px;
}
#line {
  width: 100%;
  height: 0.1px;
  background-color: #e5e5e5;
  margin-bottom: 20px;
}
#process {
  margin-bottom: 20px;
}
.block2 {
  margin-top: 30px;
  text-align: right;
}
</style>
